(function() {
	
	if (!window.CJ) {
		window.CJ = {};
	}
	//부가정보
	function Content () {
		this.name = 'Content';
		this.rootID = "#vod .info";
		this.rootElem = $(this.rootID+"  ol");
		this.moveDistance = -208;
		this.pageUnitCount = 5;
		this.bindEvent();
	}
	Content.totalCount = 0;
	Content.pageSize = 5;
	Content.pageNo = 0;
	Content.setID = function (id) {
		this.lastID = id;
	};
	Content.getData = function (pID) {
		if (Content.lastID != pID) {
			this.totalCount = 0;
			this.pageNo = 0;
		}
		CJ.HttpJson.get({
			type: 'PROGRAMCONTENTSLIST',
			param: {
				programid: pID,
				pageSize: this.pageSize,
				pageNo: this.pageNo + 1
			},
			success:  function (json) {
				Content.setID(pID);
				Content.successCB(json);
			},
			complete: function (){
			}
		});
	};
	Content.getMore = function () {
		if (this.totalPage != this.pageNo) {
			this.getData(Content.lastID);
		}
	};
	Content.successCB = function (json) {
		this.totalCount = parseInt(json.total_count);
		this.totalPage =  parseInt(json.page_info.total_page);
		this.pageNo =  parseInt(json.page_info.page);
		CJ.Scene["Content"].render(json.programcontentslist);
	};
	Content.prototype = new CJ.Horizon();
	Content.prototype.bindEvent = function () {
		var self = this;
			//좌우측 페이징 버튼 Click
		$(this.rootID+ " .btn_prev").on('click', function(){
			//self.extend();
			CJ.Scene["Qmenu"].removeFocus();
			CJ.Scene.setDelegate(CJ.Scene[self.name]);
			CJ.Horizon.prototype.pageUp.call(self);
		});
		$(this.rootID+ " .btn_next").on('click', function(){
			//self.extend();
			CJ.Scene["Qmenu"].removeFocus();
			CJ.Scene.setDelegate(CJ.Scene[self.name]);
			CJ.Horizon.prototype.pageDown.call(self);
		});
		
		//좌우측 페이징 버튼  mouseover
		$(this.rootID+ " .btn_prev").on('mouseenter', function(){
			//self.extend();
			CJ.Scene["Qmenu"].removeFocus();
			CJ.Scene.setDelegate(CJ.Scene[self.name]);
			$('.focus', this.rootID).removeClass('focus');
			$(this).addClass('focus');
		});
		$(this.rootID+ " .btn_next").on('mouseenter', function(){
			//self.extend();
			CJ.Scene["Qmenu"].removeFocus();
			CJ.Scene.setDelegate(CJ.Scene[self.name]);
			$('.focus', this.rootID).removeClass('focus');
			$(this).addClass('focus');
		});

		//list mouseover
		$(this.rootElem).on('mouseenter', 'li', function(){
			//하위 모든 포커스 제거
			CJ.Scene["Qmenu"].removeFocus();
			CJ.Scene.setDelegate(CJ.Scene[self.name]);
			$('.focus', this.rootID).removeClass('focus');
			$(this).siblings().removeClass('select focus');
			$(this).addClass('select focus');
		});
		CJ.Horizon.prototype.bindEvent.call(this);
	};
	Content.prototype.render = function (lists) {
		var childCount = this.rootElem.children().length;
		var method =  childCount > 0 ? 'append' : 'html';
		$( this.rootElem )[method](
			$.render.contentsTemplate( lists )
		);
		if (method == 'html') {
			var obj = CJ.getStaticObject(this.name);
			var total = obj.totalCount;
			this.rootElem.css({'width': Math.abs(total * this.moveDistance)+1+ 'px', 'left': '0px'});
			$('li', this.rootElem).removeClass('select').eq(0).addClass('select');
		}
	};
	Content.prototype.setFocus = function() {
		var elem = $('li:first-child', this.rootElem ).addClass('focus').get(0);
		CJ.Horizon.prototype.setFocus.call(this, elem);
	};
	Content.prototype.extend = function() {
		Content.getMore();
	};
	Content.prototype.back = function () {
		$(this.rootID).removeClass('focus');
		CJ.plugin.Player.channeling();
		CJ.Scene.videoPlayBackCB();
	};
	Content.prototype.up = function () {
		$(this.rootID + ' .focus').removeClass('focus');
		CJ.Scene.qmenu();
	};
	Content.prototype.left = function() {
		var now = $('#vod .info .focus');
		if (now.hasClass('btn_next')) {				 			//컨텐츠로
			now.removeClass('focus');
			CJ.Horizon.prototype.entryList.call(this);
		} else if (now.hasClass('select')){					//컨텐츠에서 좌측 버튼
			CJ.Horizon.prototype.left.call(this);
		}
	};
	Content.prototype.right = function () {
		var now = $('#vod .info .focus');
		if (now.hasClass('btn_prev')){				//컨텐츠로
			now.removeClass('focus');
			CJ.Horizon.prototype.entryList.call(this);
		} else if (now.hasClass('select')) {				//리스트 이동
			CJ.Horizon.prototype.right.call(this);
		}
	};
	Content.prototype.enter = function (evt) {
		this.extend();
		var now = $(this.rootID + ' .focus');
		if (now.hasClass('btn_prev')){
			CJ.Horizon.prototype.pageUp.call(this);
		} else if (now.hasClass('select')) {
			//컨텐츠 선택
			
		} else if (now.hasClass('btn_next')){
			CJ.Horizon.prototype.pageDown.call(this);
		} else {
			//카테고리 선택
		}
	};

	CJ.Content = Content;

	$.extend(CJ.Scene, {
							content: function(){
								$('li.focus', this["Content"].rootElem).removeClass('focus');
								//$('#vod .info .btn_prev').addClass('focus');
								this["Content"].setFocus();
								this.setDelegate(this["Content"]);
							}
						});


	$(document).ready(function(){
		CJ.Scene["Content"] = new CJ.Content();
	});
})();